package com.jt.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * Created by FanJia on 2020/11/12 14:05
 */
public class ObjectMapperUtil {
    private static final ObjectMapper MAPPER = new ObjectMapper();

    public static String toJSON(Object target){

        try {
            return  MAPPER.writeValueAsString(target);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    public static <T> T toObject(String s,Class<T> target){

        try {
            return  MAPPER.readValue(s, target);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }



}
